import requests
from itsdangerous import TimedJSONWebSignatureSerializer, SignatureExpired
import time
from meiduo_mall import settings
# 获取邮箱激活验证的实例
def generic_email_verify_token(user_id):
    # 1. 创建实例
    s = TimedJSONWebSignatureSerializer(secret_key=settings.SECRET_KEY, expires_in=3600*24)
    # 2. 加密数据
    data = s.dumps({'user_id': user_id})
    return data.decode()


def check_verify_token(token):
    # 创建实例
    # 解密数据--有异常
    s = TimedJSONWebSignatureSerializer(secret_key=settings.SECRET_KEY, expires_in=3600*24)
    try:
        result = s.loads(token)
    except Exception as e:
        return None
    return result.get('user_id')


